package com.example.gsp.mybatis;

import com.example.gsp.dao.SwitchDao;
import com.example.gsp.entity.Switch;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class Demo {

    private SqlSessionFactory sqlSessionFactory;

    @Before
    public void init() throws IOException {
        String resource = "mapper/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        inputStream.close();
    }

    @Test
    public void testMapping(){
        SqlSession sqlSession = sqlSessionFactory.openSession();
        SwitchDao switchDao = sqlSession.getMapper(SwitchDao.class);
        List<Switch> switchList = switchDao.selectSwitchMap();
        System.out.println(switchList);                                                                                                        

    }


}
